import java.awt.*;
import java.awt.event.MouseEvent;

public class DessinHexagone extends Dessin{
	private static final long serialVersionUID = 1L;
	
	Shape shape;
	
	public boolean contains(int x, int y)
	{
		if(shape == null || ! shape.getBounds().getSize().equals(getSize()))
		{
			float base = Math.min(this.getWidth(), this.getHeight());
			float SQRT3 = (float) Math.sqrt(3);
			float hight = (base/2)*SQRT3/2;
			float delta = (base/2)-hight;
			
			int[] xTmp = {0, (int) Math.floor(base/4), (int) Math.floor((base/4)*3), (int) Math.floor(base), (int) Math.floor((base/4)*3), (int) Math.floor(base/4)};
			
			base = this.getHeight();
			hight = (base/2)*SQRT3/2;
			delta = (base/2)-hight;
			int[] yTmp = {(int) Math.floor(base/2), (int) Math.floor(delta), (int) Math.floor(delta), (int) Math.floor(base/2), (int) Math.floor(base-delta), (int) Math.floor(base-delta)};

			shape = new Polygon(xTmp, yTmp, 6);
		}
		return shape.contains(x, y);
	}
	
	public void paint(Graphics g)
	{
		this.setOpaque(false);
		g.setColor(defaultColor);
		
		float base = this.getWidth();
		float SQRT3 = (float) Math.sqrt(3);
		float hight = (base/2)*SQRT3/2;
		float delta = (base/2)-hight;
		
		int[] x = {0, (int) Math.floor(base/4), (int) Math.floor((base/4)*3), (int) Math.floor(base), (int) Math.floor((base/4)*3), (int) Math.floor(base/4)};
		
		base = this.getHeight();
		hight = (base/2)*SQRT3/2;
		delta = (base/2)-hight;
		int[] y = {(int) Math.floor(base/2), (int) Math.floor(delta), (int) Math.floor(delta), (int) Math.floor(base/2), (int) Math.floor(base-delta), (int) Math.floor(base-delta)};

		g.fillPolygon(x, y, 6);
	}

	public void mouseDragged(MouseEvent e) {
		DessinHexagone.this.setBounds(DessinHexagone.this.getX() + (e.getX() - xDebut), DessinHexagone.this.getY() + (e.getY() - yDebut), DessinHexagone.this.getWidth(), DessinHexagone.this.getHeight());
		
		repaint();
	}

	public void mousePressed(MouseEvent e) {
		xDebut = e.getX();
		yDebut = e.getY();
	}
}
